home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / haeberli / fonttools / clonewid.c < prev    next >
C/C++ Source or Header  |  1994-08-01  |  3KB  |  152 lines

  1. /*
  2.  * Copyright 1991, 1992, 1993, 1994, Silicon Graphics, Inc.
  3.  * All Rights Reserved.
  4.  *
  5.  * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  6.  * the contents of this file may not be disclosed to third parties, copied or
  7.  * duplicated in any form, in whole or in part, without the prior written
  8.  * permission of Silicon Graphics, Inc.
  9.  *
  10.  * RESTRICTED RIGHTS LEGEND:
  11.  * Use, duplication or disclosure by the Government is subject to restrictions
  12.  * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  13.  * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  14.  * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  15.  * rights reserved under the Copyright Laws of the United States.
  16.  */
  17. /*
  18.  *    clonewid - 
  19.  *        Use widths from another font.
  20.  *
  21.  *                Paul Haeberli - 1991
  22.  *
  23.  */
  24. #include "stdio.h"
  25. #include "objfnt.h"
  26.  
  27. objfnt *ofnt, *wfnt;
  28.  
  29. main(argc,argv)
  30. int argc;
  31. char **argv;
  32. {
  33.     short val;
  34.     float pos;
  35.     float ixpos, iypos;
  36.     float xpos, ypos;
  37.     int dx, dy;
  38.     int xmove, ymove;
  39.  
  40.     if( argc<4 ) {
  41.     fprintf(stderr,"usage: clonewid orig.of width.of out.of\n");
  42.     exit(1);
  43.     } 
  44.     ofnt = readobjfnt(argv[1]);
  45.     if(!ofnt) {
  46.     fprintf(stderr,"clonewid: can't open input file\n");
  47.     exit(1);
  48.     } 
  49.     wfnt = readobjfnt(argv[2]);
  50.     if(!wfnt) {
  51.     fprintf(stderr,"clonewid: can't open input file\n");
  52.     exit(1);
  53.     } 
  54.     clonewidths(ofnt,wfnt);
  55.     writeobjfnt(argv[3],ofnt);
  56. }
  57.  
  58. mag(v)
  59. int v;
  60. {
  61.    if(v<0)
  62.     return -v;
  63.     else
  64.     return v;
  65. }
  66.  
  67. clonewidths(ofnt,wfnt)
  68. objfnt *ofnt, *wfnt;
  69. {
  70.     int i, dx, dy;
  71.     chardesc *ocd, *wcd;
  72.     int oxmin, oxmax, oymin, oymax;
  73.     int wxmin, wxmax, wymin, wymax;
  74.     int mindx, maxdx, mindy, maxdy;
  75.  
  76.     for(i=ofnt->charmin; i<=ofnt->charmax; i++) {
  77.     ocd = getchardesc(ofnt,i);
  78.     wcd = getchardesc(wfnt,i);
  79.     if(ocd && wcd) {
  80.         fincharbbox(ofnt,i,&oxmin,&oxmax,&oymin,&oymax);
  81.         fincharbbox(wfnt,i,&wxmin,&wxmax,&wymin,&wymax);
  82.         mindx = wxmin-oxmin;
  83.         maxdx = wxmax-oxmax;
  84.         mindy = wymin-oymin;
  85.         maxdy = wymax-oymax;
  86.         if(mag(maxdx)<mag(mindx))
  87.         dx = maxdx;
  88.         else
  89.         dx = mindx;
  90.         if(mag(maxdy)<mag(mindy))
  91.         dy = maxdy;
  92.         else
  93.         dy = mindy;
  94.         ocd->movex = wcd->movex;
  95.         ocd->movey = wcd->movey;
  96.         translatechar(ofnt,i,dx,dy);
  97.     }
  98.     }
  99. }
  100.  
  101. static int xmin, xmax, ymin, ymax;
  102.  
  103. static bboxcalc(v)
  104. short v[2];
  105. {
  106.     if(v[0]<xmin)
  107.         xmin = v[0];
  108.     if(v[1]<ymin)
  109.         ymin = v[1];
  110.     if(v[0]>xmax)
  111.         xmax = v[0];
  112.     if(v[1]>ymax)
  113.         ymax = v[1];
  114. }
  115.  
  116.  
  117. int xtrans, ytrans;
  118.  
  119. static warpfunc(s)
  120. short s[2];
  121. {
  122.     s[0] = s[0] + xtrans;
  123.     s[1] = s[1] + ytrans;
  124. }
  125.  
  126. translatechar(fnt,c,dx,dy)
  127. objfnt *fnt;
  128. int c, dx, dy;
  129. {
  130.     xtrans = dx;
  131.     ytrans = dy;
  132.     applytocharverts(fnt,c,warpfunc);
  133. }
  134.  
  135. fincharbbox(fnt,c,rxmin,rxmax,rymin,rymax)
  136. objfnt *fnt;
  137. int c;
  138. int *rxmin, *rxmax, *rymin, *rymax;
  139. {
  140.     chardesc *cd;
  141.  
  142.     xmin = ymin = NOBBOX;
  143.     xmax = ymax = -NOBBOX;
  144.     cd = getchardesc(fnt,c);
  145.     if(cd)
  146.     applytocharverts(fnt,c,bboxcalc);
  147.     *rxmin = xmin;
  148.     *rxmax = xmax;
  149.     *rymin = ymin;
  150.     *rymax = ymax;
  151. }
  152.